//
//  ShoppingDeleteView.m
//  YYBG_IOS
//
//  Created by wyl on 2017/3/9.
//  Copyright © 2017年 wyl. All rights reserved.
//

#import "ShoppingDeleteView.h"
#import "BSCommon.h"


@interface ShoppingDeleteView ()
@property(nonatomic,strong)  UIButton *checkBtn ;
@end

@implementation ShoppingDeleteView


-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self initDeleteView];
    }
    return self;
}


-(void)initDeleteView{
    
    
    _checkBtn = [[UIButton alloc]init];
    _checkBtn.width = CGRectGetHeight(self.frame) *2 / 5 ;
    _checkBtn.height = CGRectGetHeight(self.frame) *2 / 5  ;
    _checkBtn.x = 20 ;
    _checkBtn.centerY = CGRectGetHeight(self.frame) / 2  ;
    [_checkBtn setImage:ImageNamed(@"checkbox1") forState:UIControlStateNormal];
    [_checkBtn setImage:ImageNamed(@"checkbox2") forState:UIControlStateSelected];
    [_checkBtn setImage:ImageNamed(@"checkbox2") forState:UIControlStateHighlighted];
    [_checkBtn addTarget:self action:@selector(chooseAll:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_checkBtn];
    
    UILabel *heji = [[UILabel alloc]init];
    [heji setText:@"全选"];
    heji.systemFont = 13 ;
    [heji sizeToFit];
    heji.x = CGRectGetMaxX(_checkBtn.frame) + 5;
    heji.centerY =CGRectGetHeight(self.frame) / 2 ;
    [self addSubview:heji];
   
    
    UIButton *deleteBtn = [[UIButton alloc]init];
    deleteBtn.width = 70 ;
    deleteBtn.height = 26 ;
    deleteBtn.x = (APPWIDTH - 80) ;
    deleteBtn.titleLabel.systemFont = 13 ;
    deleteBtn.centerY =  CGRectGetHeight(self.frame) / 2  ;
    [deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
    [deleteBtn addTarget:self action:@selector(deleteAll) forControlEvents:UIControlEventTouchUpInside];
    deleteBtn.backgroundColor = [UIColor orangeColor];
    deleteBtn.layer.cornerRadius = deleteBtn.height / 2;
    [self addSubview:deleteBtn];
}

-(void)chooseAll:(UIButton *)sender{
    if (sender.isSelected) {
        [sender setSelected:NO];
        [self.delegate chooseDeleteAll:NO];
    }else {
        [sender setSelected:YES];
        [self.delegate chooseDeleteAll:YES];
    }
}
-(void)deleteAll{
    [self.delegate deleteAllCartShopCallBack];
    
}

-(void)setAllChoose:(BOOL)isChoose{
    if (isChoose) {
        [_checkBtn  setSelected:YES];
    }else {
        [_checkBtn setSelected:NO];
    }
}
@end
